package ScalaStudy.chapter06

object test14_TraitMix {
  def main(args: Array[String]): Unit = {


    /////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////   特质混入 ///////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////


    val student = new Student14

    println("=========== 类中自身方法 ============")

    student.study()

    println("=========== Knowledge特质 ============")

    student.increase()

    println("============Young 特质===========")

    student.play()
    student.dating()

    println("============  动态混入  ===========")    //在实例化时，将特质混入，跟匿名子类有点像

    val studentWithTalent = new Student14 with Talent{
      override def dancing(): Unit = {
        println("student is good at dancing")
      }
      override def singing(): Unit = {
        println("student is good at singing")
      }
    }

    println("============Talent 特质===========")

    studentWithTalent.singing()
    studentWithTalent.dancing()




  }
}

//定义一个特质
trait Knowledge{
  var Score : Int = 0
  def increase(): Unit
}

class Student14 extends Person13 with Young with Knowledge {    //特质混入，调用test13文件中的类
  //实现抽象方法
  def dating():Unit = {
    println(s"${name}和女孩约会中")
  }
  //重写并实现抽象属性
  override val name: String = "A学生"
  //定义新方法
  def study():Unit = {
    println(s"${age}的${name}正在学习")
  }
  //重写父类方法
  override def sayHello():Unit = {
    super.sayHello()
    println("重写: hello from student: " + name)
  }

  //实现特质中的抽象方法
  override def increase(): Unit = {
    Score = Score + 1
    println(s"${name}的分数为${Score}")
  }

}

trait Talent{
  def singing():Unit
  def dancing():Unit
}
